<template>
	<view class="resetPassword">
		<view class="reset-form box">
			<!-- <view class="password-old password">
				<input v-model="resetForm.passwordold" type="password" class="uni-input" placeholder="输入旧密码" />
			</view> -->
			<view class="password password-new1">
				<input v-model="resetForm.password1" type="password" class="uni-input" placeholder="新密码 (6至20位数字或字母组合)" />
			</view>
			<view class="password password-new2">
				<input v-model="resetForm.password2" type="password" class="uni-input" placeholder="再次输入新密码" />
			</view>
		</view>
		<div class="login-btn box" @click="submit">确 定</div>
	</view>
</template>

<script>
	import {resetPassword} from '../../untils/api.js'
	export default {
		data() {
			return {
				resetForm:{
					password1:'',
					password2:''
				},
				userId:''
			};
		},
		onReady() {
			this.userId = uni.getStorageSync('userInfo').userId
			console.log(uni.getStorageSync('userInfo'));
		},
		methods:{
			submit() {
				if(!this.resetForm.password1) return uni.showToast({
					title:'请填写新密码',
					icon:'none'
				})
				if(!this.resetForm.password2) return uni.showToast({
					title:'请确认新密码',
					icon:'none'
				})
				if(this.resetForm.password2 !== this.resetForm.password1) {
					return uni.showToast({
						title:'两次密码不一致',
						icon:'none'
					})
				}
				resetPassword({id:this.userId,password:this.resetForm.password1}).then(res => {
					console.log(res,'reess');
					if(res.code == 200) {
						uni.showToast({
							title:'操作成功,请重新登录',
							icon:'none'
						})
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/login/index'
							})
						},500)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login-btn {
		margin-top: 20px;
		display: flex;
		justify-content: center;
		align-items: center;
		height: 45px;
		background: #00B23C;
		border-radius: 8px;
		font-weight: 500;
		font-size: 16px;
		color: #FFFFFF;
	}
.resetPassword {
	height: 100%;
	overflow: hidden;
	background: #F4F5F5;
	.reset-form {
		margin-top: 14rpx;
		.password {
			height: 114rpx;
			margin-left: 30rpx;
			display: flex;
			align-items: center;
			input {
				width: 100%;
			}
		}
		.password-old ,.password-new1 {
			border-bottom: 1rpx solid #ECECEC;
		}
		
	}
}
</style>
